#!/bin/bash
usage() {
    echo "Usage: sign-repo.sh repo-file.txt"
    echo "Signed file is on stdout"
}

APT_KEYRING=/etc/apt/trusted.gpg
DEVSCRIPT=$HOME/.devscripts

if [ -r "$DEVSCRIPT" ]; then
    . "$DEVSCRIPT"
fi


REPO_FILE="$1"

if [ -z "$REPO_FILE" ]; then
    usage
    exit 1
fi

if [ "$REPO_FILE" = "-" ]; then
    REPO_FILE="/dev/stdin"
fi

if [ ! -z "$DEBSIGN_KEYID" ]; then
    KEY_ID="--default-key $DEBSIGN_KEYID"
else
    KEY_ID=""
fi

gpg $KEY_ID --clearsign <"$REPO_FILE"